import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/app_store/api_app_store_purchased_subscription_status.dart';

const kApiAppStorePurchasedSubscriptionActiveStatusValue = 'active';
const kApiAppStorePurchasedSubscriptionExpiredStatusValue = 'expired';
const kApiAppStorePurchasedSubscriptionInBillingRetryPeriodStatusValue = 'in_billing_retry_period';
const kApiAppStorePurchasedSubscriptionInGracePeriodStatusValue = 'in_grace_period';
const kApiAppStorePurchasedSubscriptionRevokedStatusValue = 'revoked';

class ApiAppStorePurchasedSubscriptionStatusDto extends Equatable {
  const ApiAppStorePurchasedSubscriptionStatusDto._internal({
    required this.statusString,
  });

  final String statusString;

  @override
  List<Object?> get props {
    return [
      statusString,
    ];
  }

  factory ApiAppStorePurchasedSubscriptionStatusDto.fromEntity(
      ApiAppStorePurchasedSubscriptionStatus status) {
    late final String statusString;

    if (status == ApiAppStorePurchasedSubscriptionStatus.active) {
      statusString = kApiAppStorePurchasedSubscriptionActiveStatusValue;
    } else if (status == ApiAppStorePurchasedSubscriptionStatus.expired) {
      statusString = kApiAppStorePurchasedSubscriptionExpiredStatusValue;
    } else if (status == ApiAppStorePurchasedSubscriptionStatus.inBillingRetryPeriod) {
      statusString = kApiAppStorePurchasedSubscriptionInBillingRetryPeriodStatusValue;
    } else if (status == ApiAppStorePurchasedSubscriptionStatus.inGracePeriod) {
      statusString = kApiAppStorePurchasedSubscriptionInGracePeriodStatusValue;
    } else if (status == ApiAppStorePurchasedSubscriptionStatus.revoked) {
      statusString = kApiAppStorePurchasedSubscriptionRevokedStatusValue;
    }

    return ApiAppStorePurchasedSubscriptionStatusDto._internal(
      statusString: statusString,
    );
  }

  @override
  String toString() {
    return statusString;
  }
}
